%% This is file trackchanges.sty
%% 
%% Copyright (C) 2006-2007 Felix Salfner (salfner@informatik.hu-berlin.de)
%%
%% This program is free software; you can redistribute it and/or modify it under the terms 
%% of the GNU General Public License as published by the Free Software Foundation; either 
%% version 2 of the License, or (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
%% without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
%% See the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License along with this program; 
%% if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
%% MA 02111-1307 USA
%%
%% For further info / comments please contact: Felix Salfner (salfner@informatik.hu-berlin.de)
%%
%% version 0.6, 2007-06-13
%% written by Felix Salfner
%%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{trackchanges}
   [2007/06/13 v0.6 Track changes file ]
%%
\RequirePackage{color}
\RequirePackage{ifthen}
\RequirePackage{calc}
%%\RequirePackage{geometry}
\RequirePackage[normalem]{ulem}
%%
\newif\if@trackchanges
\@trackchangestrue
\newif\if@trackinmargins
\@trackinmarginsfalse
\DeclareOption{final}{\@trackchangesfalse}
\DeclareOption{margins}{\@trackinmarginstrue}
\ProcessOptions
%%
%% -------------- counters
\newcounter{userid}
\setcounter{userid}{-1}
\newcounter{changenumber}[page]
\setcounter{changenumber}{0}
\newcounter{storefootnote}
%%
%% ----------- create commands for five users
\newcommand{\initialsOne}{n/n}
\newcommand{\initialsTwo}{n/n}
\newcommand{\initialsThree}{n/n}
\newcommand{\initialsFour}{n/n}
\newcommand{\initialsFive}{n/n}
%%
%% -------------- set counter userid according to initials
\newcommand{\matchuser}[1]{%
   \ifthenelse{\equal{#1}{\initialsOne}}%
      {\setcounter{userid}{1}}%
      {\ifthenelse{\equal{#1}{\initialsTwo}}%
           {\setcounter{userid}{2}}%
           {\ifthenelse{\equal{#1}{\initialsThree}}%
                 {\setcounter{userid}{3}}%
                 {\ifthenelse{\equal{#1}{\initialsFour}}%
                       {\setcounter{userid}{4}}%
                       {\ifthenelse{\equal{#1}{\initialsFive}}%
                              {\setcounter{userid}{5}}%
                              {\setcounter{userid}{-1}}%
                       }%
                 }%
           }%
      }%
}
%%
%% --------------- define text styles for different users
\newcommand{\userformat}{%
   \ifthenelse{\value{userid} = 1}%
       {\color{blue}}%
       {\ifthenelse{\value{userid} = 2}% 
          {\color{red}}%
          {\ifthenelse{\value{userid} = 3}%
                {\color{magenta}}%
                {\ifthenelse{\value{userid} = 4}%
                     {\color{cyan}}%
                     {\ifthenelse{\value{userid} = 5}%
                          {\color{green}}%
                          {\color{black}}%
                     }%
                }%
          }%
       }%
}
%%
%% ---------------------- define the frontend command \add
%% ---------------------- usage: \add[Initials]{new text}
\newcommand{\add}[2][n/n]{%
  \if@trackchanges%
     \setcounter{storefootnote}{\value{footnote}}%
     \refstepcounter{changenumber}%
     {\matchuser{#1}\userformat%
        \renewcommand{\thefootnote}{c\arabic{changenumber}}%
        \uline{#2}%
        \if@trackinmargins
          $^{\thefootnote}$\renewcommand{\baselinestretch}{0.8}\marginpar{\userformat\tiny $^{\thefootnote}$ \textit{text added by #1}}%
        \else
          \footnote{\userformat\textit{text added by #1}}%
        \fi
     }%
     \setcounter{footnote}{\value{storefootnote}}%
  \else
%% if trackchanges is false ... print only the new text
  #2%
  \fi
}
%%
%% ---------------------- define the frontend command \remove
%% ---------------------- usage: \remove[Initials]{old text}
\newcommand{\remove}[2][n/n]{%
  \if@trackchanges
     \setcounter{storefootnote}{\value{footnote}}%
     \refstepcounter{changenumber}%
     {\matchuser{#1}\userformat%
        \renewcommand{\thefootnote}{c\arabic{changenumber}}%
        \if@trackinmargins
          $^{\thefootnote}$\renewcommand{\baselinestretch}{0.8}\marginpar{\userformat\tiny $^{\thefootnote}$\textit{removed text by #1:} #2}%
        \else
          \footnote{\userformat\textit{removed text by #1:} #2}%
        \fi
     }%
     \setcounter{footnote}{\value{storefootnote}}%
  \else
%% if trackchanges is false ... print only the new text
  #2%
  \fi
}
%%
%% ---------------------- define the frontend command \change
%% ---------------------- usage: \change[Initials]{original text}{new text}
\newcommand{\change}[3][n/n]{%
  \if@trackchanges
     \setcounter{storefootnote}{\value{footnote}}%
     \refstepcounter{changenumber}%
     {\matchuser{#1}\userformat%
        \renewcommand{\thefootnote}{c\arabic{changenumber}}%
        \uline{#3}%
        \if@trackinmargins
          $^{\thefootnote}$\renewcommand{\baselinestretch}{0.8}\marginpar{\userformat\tiny $^{\thefootnote}$#1: #2}%
        \else
          \footnote{\userformat #1: #2}%
        \fi
     }%
     \setcounter{footnote}{\value{storefootnote}}%
  \else
%% if trackchanges is false ... print only the new textwidth
  #3%
  \fi
}
%%
%% ----------------- define frontend command \note
%% ---------------------- usage: \note[Initials]{note text}
\newcommand{\note}[2][n/n]{%
  \if@trackchanges%
     \setcounter{storefootnote}{\value{footnote}}%
     \refstepcounter{changenumber}%
     {\matchuser{#1}\userformat%
        \renewcommand{\thefootnote}{c\arabic{changenumber}}%
        \if@trackinmargins%
          $^{\thefootnote}$\renewcommand{\baselinestretch}{0.8}\marginpar{\userformat\tiny $^{\thefootnote}$#1: #2}%
        \else%
          \footnote{\userformat #1: #2}%
        \fi%
     }%
     \setcounter{footnote}{\value{storefootnote}}%
  \else%
%% if trackchanges is false ... do not print notes
  \fi%
}%
%%
%% ----------------- define frontend command \annote
%% ---------------------- usage: \annote[Initials]{highlighted text}{note text}
\newcommand{\annote}[3][n/n]{%
  \if@trackchanges%
     \setcounter{storefootnote}{\value{footnote}}%
     \refstepcounter{changenumber}%
     {\matchuser{#1}\userformat%
	\uline{#2}%
        \renewcommand{\thefootnote}{c\arabic{changenumber}}%
        \if@trackinmargins%
          $^{\thefootnote}$\renewcommand{\baselinestretch}{0.8}\marginpar{\userformat\tiny $^{\thefootnote}$#1: #3}%
        \else%
          \footnote{\userformat #1: #3}%
        \fi%
     }%
     \setcounter{footnote}{\value{storefootnote}}%
  \else%
%% if trackchanges is false ... do not print notes
  \fi%
}%
%%
%%
\AtEndOfClass{
  \if@trackchanges
    \if@trackinmargins
    	\setlength{\oddsidemargin}{5mm}
      \setlength{\marginparwidth}{\paperwidth}
      \addtolength{\marginparwidth}{-5mm}
      \addtolength{\marginparwidth}{-\hoffset}
      \addtolength{\marginparwidth}{-1in}
      \addtolength{\marginparwidth}{-\oddsidemargin}
      \addtolength{\marginparwidth}{-\textwidth}
			\addtolength{\marginparwidth}{-\marginparsep}
    \else
    \fi
  \fi
}
%%
%%
%% End of file trackchanges.sty
